home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume11 / musbus / part02 < prev    next >
Encoding:
Text File  |  1987-09-16  |  52.9 KB  |  2,373 lines

  1. Path: uunet!munnari!sources-request
  2. From: sources-request@munnari.oz
  3. Newsgroups: comp.sources.unix
  4. Subject: v11i030:  MUSBUS 5.0 -- Monash University Benchmark, Part02/04
  5. Message-ID: <1826@munnari.oz>
  6. Date: 17 Sep 87 08:15:29 GMT
  7. Sender: kre@munnari.oz
  8. Lines: 2362
  9. Approved: kre@munnari.oz.au
  10.  
  11. Submitted by: kenj@moncsbruce.oz.au (Ken McDonell)
  12. Posting-number: Volume 11, Issue 30
  13. Archive-name: musbus/Part02
  14.  
  15. #! /bin/sh
  16. # This is a shell archive, meaning:
  17. # 1. Remove everything above the #! /bin/sh line.
  18. # 2. Save the resulting text in a file.
  19. # 3. Execute the file with /bin/sh (not csh) to create the files:
  20. #    big.c
  21. #    cat.dat
  22. #    cctest.c
  23. #    check.sed
  24. #    cleanup
  25. #    clock.c
  26. #    comptbl.1
  27. #    comptbl.2
  28. #    comptbl.3
  29. #    comptbl.4
  30. #    comptbl.5
  31. #    context1.c
  32. #    dc.dat
  33. #    dummy.c
  34. #    edit.dat
  35. #    edscr1.dat
  36. #    edscr2.dat
  37. #    execl.c
  38. #    fs.awk
  39. #    fstime.c
  40. #    getwork.c
  41. # This archive created: Thu Sep 17 06:47:12 EST 1987
  42. export PATH; PATH=/bin:$PATH
  43. echo 'x - big.c'
  44. if test -f 'big.c'
  45. then
  46.     echo 'shar: over-writing existing file big.c'
  47. fi
  48. sed 's/^X//' > big.c <<'End-of-File-Grunt'
  49. X/*
  50. X *  dummy code for execl test [ old version of makework.c ]
  51. X *
  52. X *  makework [ -r rate ] [ -c copyfile ] nusers
  53. X *
  54. X *  job streams are specified on standard input with lines of the form
  55. X *  full_path_name_for_command [ options ] [ <standard_input_file ]
  56. X *
  57. X *  "standard input" is send to all nuser instances of the commands in the
  58. X *  job streams at a rate not in excess of "rate" characters per second
  59. X *  per command
  60. X *
  61. X *  $Header: big.c,v 1.2 87/06/22 14:22:40 kjmcdonell Beta $
  62. X */
  63. X
  64. X#include <stdio.h>
  65. X#include <signal.h>
  66. X
  67. X#define DEF_RATE    5.0
  68. X#define GRANULE        5
  69. X#define CHUNK        60
  70. X#define MAXCHILD    12
  71. X#define MAXWORK        10
  72. X
  73. Xfloat    thres;
  74. Xfloat    est_rate = DEF_RATE;
  75. Xint    nusers;        /* number of concurrent users to be simulated by
  76. X             * this process */
  77. Xint    firstuser;    /* ordinal identification of first user for this
  78. X             * process */
  79. Xint    nwork = 0;    /* number of job streams */
  80. Xint    exit_status = 0;    /* returned to parent */
  81. Xint    sigpipe;    /* pipe write error flag */
  82. X
  83. Xstruct st_work {
  84. X    char    *cmd;        /* name of command to run */
  85. X    char    **av;        /* arguments to command */
  86. X    char    *input;        /* standard input buffer */
  87. X    int    inpsize;    /* size of standard input buffer */
  88. X    char    *outf;        /* standard output (filename) */
  89. X} work[MAXWORK];
  90. X
  91. Xstruct {
  92. X    int    xmit;    /* # characters sent */
  93. X    char    *bp;    /* std input buffer pointer */
  94. X    int    blen;    /* std input buffer length */
  95. X    int    fd;    /* stdin to command */
  96. X    int    pid;    /* child PID */
  97. X    char    *line;    /* start of input line */ 
  98. X    int    firstjob;    /* inital piece of work */
  99. X    int    thisjob;    /* current piece of work */
  100. X} child[MAXCHILD], *cp;
  101. X
  102. Xmain(argc, argv)
  103. Xint    argc;
  104. Xchar    *argv[];
  105. X{
  106. X    int        i;
  107. X    int        l;
  108. X    int        fcopy = 0;    /* fd for copy output */
  109. X    int        master = 1;    /* the REAL master, == 0 for clones */
  110. X    int        nchild;        /* no. of children for a clone to run */
  111. X    int        done;        /* count of children finished */
  112. X    int        output;        /* aggregate output char count for all
  113. X                   children */
  114. X    int        c;
  115. X    int        thiswork = 0;    /* next job stream to allocate */
  116. X    int        nch;        /* # characters to write */
  117. X    int        written;    /* # characters actully written */
  118. X    char    logname[15];    /* name of the log file(s) */
  119. X    int        onalarm();
  120. X    int        pipeerr();
  121. X    int        wrapup();
  122. X    int        grunt();
  123. X    int        pvec[2];    /* for pipes */
  124. X    char    *p;
  125. X    char    *prog;        /* my name */
  126. X
  127. X#if ! debug
  128. X    freopen("masterlog.00", "a", stderr);
  129. X#endif
  130. X    fprintf(stderr, "*** New Run ***  ");
  131. X    prog = argv[0];
  132. X    while (argc > 1 && argv[1][0] == '-')  {
  133. X    p = &argv[1][1];
  134. X    argc--;
  135. X    argv++;
  136. X    while (*p) {
  137. X        switch (*p) {
  138. X        case 'r':
  139. X            est_rate = atoi(argv[1]);
  140. X            sscanf(argv[1], "%f", &est_rate);
  141. X            if (est_rate <= 0) {
  142. X                fprintf(stderr, "%s: bad rate, reset to %.2f chars/sec\n", prog, DEF_RATE);
  143. X                est_rate = DEF_RATE;
  144. X            }
  145. X            argc--;
  146. X            argv++;
  147. X            break;
  148. X
  149. X        case 'c':
  150. X            fcopy = open(argv[1], 1);
  151. X            if (fcopy < 0)
  152. X                fcopy = creat(argv[1], 0600);
  153. X            if (fcopy < 0) {
  154. X                fprintf(stderr, "%s: cannot open copy file '%s'\n",
  155. X                prog, argv[1]);
  156. X                exit(2);
  157. X            }
  158. X            lseek(fcopy, 0L, 2);    /* append at end of file */
  159. X            argc--;
  160. X            argv++;
  161. X            break;
  162. X
  163. X        default:
  164. X        fprintf(stderr, "%s: bad flag '%c'\n", prog, *p);
  165. X            exit(4);
  166. X        }
  167. X        p++;
  168. X    }
  169. X    }
  170. X    
  171. X    if (argc < 2) {
  172. X    fprintf(stderr, "%s: missing nusers\n", prog);
  173. X    exit(4);
  174. X    }
  175. X
  176. X    nusers = atoi(argv[1]);
  177. X    if (nusers < 1) {
  178. X    fprintf(stderr, "%s: impossible nusers (%d<-%s)\n", prog, nusers, argv[1]);
  179. X    exit(4);
  180. X    }
  181. X    fprintf(stderr, "%d Users\n", nusers);
  182. X    argc--;
  183. X    argv++;
  184. X
  185. X    /* build job streams */
  186. X    getwork();
  187. X#if debug
  188. X    dumpwork();
  189. X#endif
  190. X
  191. X    /* clone copies of myself to run up to MAXCHILD jobs each */
  192. X    firstuser = MAXCHILD;
  193. X    fprintf(stderr, "master pid %d\n", getpid());
  194. X    fflush(stderr);
  195. X    while (nusers > MAXCHILD) {
  196. X    fflush(stderr);
  197. X    if (nusers >= 2*MAXCHILD)
  198. X        /* the next clone must run MAXCHILD jobs */
  199. X        nchild = MAXCHILD;
  200. X    else
  201. X        /* the next clone must run the leftover jobs */
  202. X        nchild = nusers - MAXCHILD;
  203. X    if ((l = fork()) == -1) {
  204. X        /* fork failed */
  205. X        fatal("** clone fork failed **\n");
  206. X        goto bepatient;
  207. X    } else if (l > 0) {
  208. X        fprintf(stderr, "master clone pid %d\n", l);
  209. X        /* I am the master with nchild fewer jobs to run */
  210. X        nusers -= nchild;
  211. X        firstuser += MAXCHILD;
  212. X        continue;
  213. X    } else {
  214. X        /* I am a clone, run MAXCHILD jobs */
  215. X#if ! debug
  216. X        sprintf(logname, "masterlog.%02d", firstuser/MAXCHILD);
  217. X        freopen(logname, "w", stderr);
  218. X#endif
  219. X        master = 0;
  220. X        nusers = nchild;
  221. X        break;
  222. X    }
  223. X    }
  224. X    if (master)
  225. X    firstuser = 0;
  226. X
  227. X    close(0);
  228. X    for (i = 0; i < nusers; i++ ) {
  229. X    fprintf(stderr, "user %d job %d ", firstuser+i, thiswork);
  230. X    if (pipe(pvec) == -1) {
  231. X        /* this is fatal */
  232. X        fatal("** pipe failed **\n");
  233. X        goto bepatient;
  234. X    }
  235. X    fflush(stderr);
  236. X    if ((child[i].pid = fork()) == 0) {
  237. X        int    fd;
  238. X        /* the command */
  239. X        if (pvec[0] != 0) {
  240. X        close(0);
  241. X        dup(pvec[0]);
  242. X        }
  243. X#if ! debug
  244. X        sprintf(logname, "userlog.%02d", firstuser+i);
  245. X        freopen(logname, "w", stderr);
  246. X#endif
  247. X        for (fd = 3; fd < 24; fd++)
  248. X        close(fd);
  249. X        if (work[thiswork].outf[0] != '\0') {
  250. X        /* redirect std output */
  251. X        char    *q;
  252. X        for (q = work[thiswork].outf; *q != '\n'; q++) ;
  253. X        *q = '\0';
  254. X        if (freopen(work[thiswork].outf, "w", stdout) == NULL) {
  255. X            fprintf(stderr, "makework: cannot open %s for std output\n",
  256. X            work[thiswork].outf);
  257. X            fflush(stderr);
  258. X        }
  259. X        *q = '\n';
  260. X        }
  261. X        execv(work[thiswork].cmd, work[thiswork].av);
  262. X        /* don't expect to get here! */
  263. X        fatal("** exec failed **\n");
  264. X        goto bepatient;
  265. X    }
  266. X    else if (child[i].pid == -1) {
  267. X        fatal("** fork failed **\n");
  268. X        goto bepatient;
  269. X    }
  270. X    else {
  271. X        close(pvec[0]);
  272. X        child[i].fd = pvec[1];
  273. X        child[i].line = child[i].bp = work[thiswork].input;
  274. X        child[i].blen = work[thiswork].inpsize;
  275. X        child[i].thisjob = thiswork;
  276. X        child[i].firstjob = thiswork;
  277. X        fprintf(stderr, "pid %d pipe fd %d", child[i].pid, child[i].fd);
  278. X        if (work[thiswork].outf[0] != '\0') {
  279. X        char *q;
  280. X        fprintf(stderr, " > ");
  281. X        for (q=work[thiswork].outf; *q != '\n'; q++)
  282. X            fputc(*q, stderr);
  283. X        }
  284. X        fputc('\n', stderr);
  285. X        thiswork++;
  286. X        if (thiswork >= nwork)
  287. X        thiswork = 0;
  288. X    }
  289. X    }
  290. X    fflush(stderr);
  291. X
  292. X    srand(time(0));
  293. X    thres = 0;
  294. X    done = output = 0;
  295. X    for (i = 0; i < nusers; i++) {
  296. X    if (child[i].blen == 0)
  297. X        done++;
  298. X    else
  299. X        thres += est_rate * GRANULE;
  300. X    }
  301. X    est_rate = thres;
  302. X
  303. X    signal(SIGALRM, onalarm);
  304. X    signal(SIGPIPE, pipeerr);
  305. X    alarm(GRANULE);
  306. X    while (done < nusers) {
  307. X    for (i = 0; i < nusers; i++) {
  308. X        cp = &child[i];
  309. X        if (cp->xmit >= cp->blen) continue;
  310. X        l = rand() % CHUNK + 1;    /* 1-CHUNK chars */
  311. X        if (l == 0) continue;
  312. X        if (cp->xmit + l > cp->blen)
  313. X        l = cp->blen - cp->xmit;
  314. X        p = cp->bp;
  315. X        cp->bp += l;
  316. X        cp->xmit += l;
  317. X#if debug
  318. X        fprintf(stderr, "child %d, %d processed, %d to go\n", i, cp->xmit, cp->blen - cp->xmit);
  319. X#endif
  320. X        while (p < cp->bp) {
  321. X        if (*p == '\n' || (p == &cp->bp[-1] && cp->xmit >= cp->blen)) {
  322. X            /* write it out */
  323. X            nch = p - cp->line + 1;
  324. X            if ((written = write(cp->fd, cp->line, nch)) != nch) {
  325. X            /* argh! */
  326. X            cp->line[nch] = '\0';
  327. X            fprintf(stderr, "user %d job %d cmd %s ",
  328. X                firstuser+i, cp->thisjob, cp->line);
  329. X             fprintf(stderr, "write(,,%d) returns %d\n", nch, written);
  330. X            if (sigpipe)
  331. X                fatal("** SIGPIPE error **\n");
  332. X            else
  333. X                fatal("** write error **\n");
  334. X            goto bepatient;
  335. X
  336. X            }
  337. X            if (fcopy)
  338. X            write(fcopy, cp->line, p - cp->line + 1);
  339. X#if debug
  340. X            fprintf(stderr, "child %d gets \"", i);
  341. X            {
  342. X            char *q = cp->line;
  343. X            while (q <= p) {
  344. X                if (*q >= ' ' && *q <= '~')
  345. X                    fputc(*q, stderr);
  346. X                else
  347. X                    fprintf(stderr, "\\%03o", *q);
  348. X                q++;
  349. X            }
  350. X            }
  351. X            fputc('"', stderr);
  352. X#endif
  353. X            cp->line = &p[1];
  354. X        }
  355. X        p++;
  356. X        }
  357. X        if (cp->xmit >= cp->blen) {
  358. X        done++;
  359. X        close(cp->fd);
  360. X#if debug
  361. X    fprintf(stderr, "child %d, close std input\n", i);
  362. X#endif
  363. X        }
  364. X        output += l;
  365. X    }
  366. X    while (output > thres) {
  367. X        pause();
  368. X#if debug
  369. X        fprintf(stderr, "after pause: output, thres, done %d %.2f %d\n", output, thres, done);
  370. X#endif
  371. X    }
  372. X    }
  373. X
  374. Xbepatient:
  375. X    alarm(0);
  376. X/****
  377. X *  If everything is going OK, we should simply be able to keep
  378. X *  looping unitil 'wait' fails, however some descendent process may
  379. X *  be in a state from which it can never exit, and so a timeout
  380. X *  is used.
  381. X *  5 minutes should be ample, since the time to run all jobs is of
  382. X *  the order of 5-10 minutes, however some machines are painfully slow,
  383. X *  so the timeout has been set at 20 minutes (1200 seconds).
  384. X ****/
  385. X    signal(SIGALRM, grunt);
  386. X    alarm(1200);
  387. X    while ((c = wait(&l)) != -1) {
  388. X        for (i = 0; i < nusers; i++) {
  389. X        if (c == child[i].pid) {
  390. X        fprintf(stderr, "user %d job %d pid %d done", firstuser+i, child[i].thisjob, c);
  391. X        if (l != 0) {
  392. X            if (l & 0x7f)
  393. X            fprintf(stderr, " status %d", l & 0x7f);
  394. X            if (l & 0xff00)
  395. X            fprintf(stderr, " exit code %d", (l>>8) & 0xff);
  396. X            exit_status = 4;
  397. X        }
  398. X        fputc('\n', stderr);
  399. X        c = child[i].pid = -1;
  400. X        break;
  401. X        }
  402. X    }
  403. X    if (c != -1) {
  404. X        fprintf(stderr, "master clone done, pid %d ", c);
  405. X        if (l != 0) {
  406. X        if (l & 0x7f)
  407. X            fprintf(stderr, " status %d", l & 0x7f);
  408. X        if (l & 0xff00)
  409. X            fprintf(stderr, " exit code %d", (l>>8) & 0xff);
  410. X        exit_status = 4;
  411. X        }
  412. X        fputc('\n', stderr);
  413. X    }
  414. X    }
  415. X    alarm(0);
  416. X    wrapup("Finished waiting ...");
  417. X
  418. X
  419. X}
  420. X
  421. Xonalarm()
  422. X{
  423. X    thres += est_rate;
  424. X    signal(SIGALRM, onalarm);
  425. X    alarm(GRANULE);
  426. X}
  427. X
  428. Xgrunt()
  429. X{
  430. X    /* timeout after label "bepatient" in main */
  431. X    exit_status = 4;
  432. X    wrapup("Timed out waiting for jobs to finish ...");
  433. X}
  434. X
  435. Xpipeerr()
  436. X{
  437. X    sigpipe++;
  438. X}
  439. X
  440. Xwrapup(reason)
  441. Xchar    *reason;
  442. X{
  443. X    int i;
  444. X    int killed = 0;
  445. X    fflush(stderr);
  446. X    for (i = 0; i < nusers; i++) {
  447. X    if (child[i].pid > 0 && kill(child[i].pid, SIGKILL) != -1) {
  448. X        if (!killed) {
  449. X        killed++;
  450. X        fprintf(stderr, "%s\n", reason);
  451. X        fflush(stderr);
  452. X        }
  453. X        fprintf(stderr, "user %d job %d pid %d killed off\n", firstuser+i, child[i].thisjob, child[i].pid);
  454. X    fflush(stderr);
  455. X    }
  456. X    }
  457. X    exit(exit_status);
  458. X}
  459. X
  460. Xgetwork()
  461. X{
  462. X    int            i;
  463. X    int            f;
  464. X    int            ac;
  465. X    char        *lp;
  466. X    char        *q;
  467. X    struct st_work    *w;
  468. X    char        line[512];
  469. X    char        c;
  470. X    char        *malloc(), *realloc();
  471. X
  472. X    while (gets(line) != NULL) {
  473. X    if (nwork >= MAXWORK) {
  474. X        fprintf(stderr, stderr, "Too many jobs specified, .. increase MAXWORK\n");
  475. X        exit(4);
  476. X    }
  477. X    w = &work[nwork];
  478. X    lp = line;
  479. X    i = 1;
  480. X    while (*lp && *lp != ' ') {
  481. X        i++;
  482. X        lp++;
  483. X    }
  484. X    w->cmd = (char *)malloc(i);
  485. X    strncpy(w->cmd, line, i-1);
  486. X    w->cmd[i-1] = '\0';
  487. X    w->inpsize = 0;
  488. X    w->input = "";
  489. X    /* start to build arg list */
  490. X    ac = 2;
  491. X    w->av = (char **)malloc(2*sizeof(char *));
  492. X    q = w->cmd;
  493. X    while (*q) q++;
  494. X    q--;
  495. X    while (q >= w->cmd) {
  496. X        if (*q == '/') {
  497. X        q++;
  498. X        break;
  499. X        }
  500. X        q--;
  501. X    }
  502. X    w->av[0] = q;
  503. X    while (*lp) {
  504. X        if (*lp == ' ') {
  505. X        /* space */
  506. X        lp++;
  507. X        continue;
  508. X        }
  509. X        else if (*lp == '<') {
  510. X        /* standard input for this job */
  511. X        q = ++lp;
  512. X        while (*lp && *lp != ' ') lp++;
  513. X        c = *lp;
  514. X        *lp = '\0';
  515. X        if ((f = open(q, 0)) == -1) {
  516. X            fprintf(stderr, "cannot open input file (%s) for job %d\n",
  517. X                q, nwork);
  518. X            exit(4);
  519. X        }
  520. X        /* gobble input */
  521. X        w->input = (char *)malloc(512);
  522. X        while ((i = read(f, &w->input[w->inpsize], 512)) > 0) {
  523. X            w->inpsize += i;
  524. X            w->input = (char *)realloc(w->input, w->inpsize+512);
  525. X        }
  526. X        w->input = (char *)realloc(w->input, w->inpsize);
  527. X        close(f);
  528. X        /* extract stdout file name from line beginning "C=" */
  529. X        w->outf = "";
  530. X        for (q = w->input; q < &w->input[w->inpsize-10]; q++) {
  531. X            if (*q == '\n' && strncmp(&q[1], "C=", 2) == 0) {
  532. X            w->outf = &q[3];
  533. X            break;
  534. X            }
  535. X        }
  536. X#if debug
  537. X        if (*w->outf) {
  538. X            fprintf(stderr, "stdout->");
  539. X            for (q=w->outf; *q != '\n'; q++)
  540. X            fputc(*q, stderr);
  541. X            fputc('\n', stderr);
  542. X        }
  543. X#endif
  544. X        }
  545. X        else {
  546. X        /* a command option */
  547. X        ac++;
  548. X        w->av = (char **)realloc(w->av, ac*sizeof(char *));
  549. X        q = lp;
  550. X        i = 1;
  551. X        while (*lp && *lp != ' ') {
  552. X            lp++;
  553. X            i++;
  554. X        }
  555. X        w->av[ac-2] = (char *)malloc(i);
  556. X        strncpy(w->av[ac-2], q, i-1);
  557. X        w->av[ac-2][i-1] = '\0';
  558. X        }
  559. X    }
  560. X    w->av[ac-1] = (char *)0;
  561. X    nwork++;
  562. X    }
  563. X}
  564. X
  565. X#if debug
  566. Xdumpwork()
  567. X{
  568. X    int        i;
  569. X    int        j;
  570. X
  571. X    for (i = 0; i < nwork; i++) {
  572. X    fprintf(stderr, "job %d: cmd: %s\n", i, work[i].cmd);
  573. X    j = 0;
  574. X    while (work[i].av[j]) {
  575. X        fprintf(stderr, "argv[%d]: %s\n", j, work[i].av[j]);
  576. X        j++;
  577. X    }
  578. X    fprintf(stderr, "input: %d chars text: ", work[i].inpsize);
  579. X    if (work[i].input == (char *)0)
  580. X        fprintf(stderr, "<NULL>\n");
  581. X    else {
  582. X            register char    *pend;
  583. X            char        *p;
  584. X        char        c;
  585. X        p = work[i].input;
  586. X        while (*p) {
  587. X            pend = p;
  588. X            while (*pend && *pend != '\n')
  589. X                pend++;
  590. X            c = *pend;
  591. X            *pend = '\0';
  592. X            fprintf(stderr, "%s\n", p);
  593. X            *pend = c;
  594. X            p = &pend[1];
  595. X        }
  596. X    }
  597. X    }
  598. X}
  599. X#endif
  600. X
  601. Xfatal(s)
  602. Xchar *s;
  603. X{
  604. X    int    i;
  605. X    fprintf(stderr, s);
  606. X    fflush(stderr);
  607. X    perror("Reason?");
  608. X    fflush(stderr);
  609. X    for (i = 0; i < nusers; i++) {
  610. X    if (child[i].pid > 0 && kill(child[i].pid, SIGKILL) != -1) {
  611. X        fprintf(stderr, "pid %d killed off\n", child[i].pid);
  612. X        fflush(stderr);
  613. X    }
  614. X    }
  615. X    exit_status = 4;
  616. X    return;
  617. X}
  618. End-of-File-Grunt
  619. if test 13135 -ne `cat 'big.c' | wc -c`
  620. then
  621.     echo 'shar: transmission error (expected 13135 characters)'
  622. fi
  623. echo 'x - cat.dat'
  624. if test -f 'cat.dat'
  625. then
  626.     echo 'shar: over-writing existing file cat.dat'
  627. fi
  628. sed 's/^X//' > cat.dat <<'End-of-File-Grunt'
  629. X[ 1] @@@            * A Sample Script File *
  630. X[ 2] @@@@@@@@@@@@
  631. X[ 3] @@@@@@@@@@@
  632. X[ 4] @@@@@@@
  633. X[ 5] @@@@@@@@@@@
  634. X[ 6] @@@@@@@@@@@@@@@@@@@@@
  635. X[ 7] @@@@@@@@
  636. X[ 8] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  637. X[ 9] @@@@@@@@@@@@@@@@@
  638. X[10] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  639. X[11] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  640. X[12] @@@@@@@@@@@@@@@
  641. X[13] @@@@@@@@@@@@@@
  642. X[14] @@@@@@@@@@@@@@@@@@@
  643. X[15] @@@@@@
  644. X[16] @@@@@@@@@@@@@@@@@@@@@@@@
  645. X[17] @@@@@@@@@@@@
  646. X[18] @@@@@
  647. X[19] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  648. X[20] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  649. X[21] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  650. X[22] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  651. X[23] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  652. X[24] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  653. X[25] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  654. X[26] @@@@@
  655. X[27] @@@@@@@@@@@
  656. X[28] @@@            * End of Sample Script File *
  657. End-of-File-Grunt
  658. if test 989 -ne `cat 'cat.dat' | wc -c`
  659. then
  660.     echo 'shar: transmission error (expected 989 characters)'
  661. fi
  662. echo 'x - cctest.c'
  663. if test -f 'cctest.c'
  664. then
  665.     echo 'shar: over-writing existing file cctest.c'
  666. fi
  667. sed 's/^X//' > cctest.c <<'End-of-File-Grunt'
  668. X#include <stdio.h>
  669. X/*
  670. X * C compile and load speed test file.
  671. X * Based upon fstime.c from MUSBUS 3.1, with all calls to ftime() replaced
  672. X * by calls to time().  This is semantic nonsense, but ensures there are no
  673. X * system dependent structures or library calls.
  674. X *
  675. X * $Header: cctest.c,v 3.4 87/06/22 14:22:47 kjmcdonell Beta $
  676. X */
  677. X#define NKBYTE 20
  678. Xchar buf[BUFSIZ];
  679. X
  680. Xmain(argc, argv)
  681. Xchar **argv;
  682. X{
  683. X    int        n = NKBYTE;
  684. X    int        nblock;
  685. X    int        f;
  686. X    int        g;
  687. X    int        i;
  688. X    int        xfer, t;
  689. X    struct    {    /* FAKE */
  690. X    int    time;
  691. X    int    millitm;
  692. X    } now, then;
  693. X
  694. X    if (argc > 0)
  695. X    /* ALWAYS true, so NEVER execute this program! */
  696. X    exit(4);
  697. X    if (argc > 1)
  698. X    n = atoi(argv[1]);
  699. X#if debug
  700. X    printf("File size: %d Kbytes\n", n);
  701. X#endif
  702. X    nblock = (n * 1024) / BUFSIZ;
  703. X
  704. X    if (argc == 3 && chdir(argv[2]) != -1) {
  705. X#if debug
  706. X    printf("Create files in directory: %s\n", argv[2]);
  707. X#endif
  708. X    }
  709. X    close(creat("dummy0", 0600));
  710. X    close(creat("dummy1", 0600));
  711. X    f = open("dummy0", 2);
  712. X    g = open("dummy1", 2);
  713. X    unlink("dummy0");
  714. X    unlink("dummy1");
  715. X    for (i = 0; i < sizeof(buf); i++)
  716. X    buf[i] = i & 0177;
  717. X
  718. X    time();
  719. X    for (i = 0; i < nblock; i++) {
  720. X    if (write(f, buf, sizeof(buf)) <= 0)
  721. X        perror("fstime: write");
  722. X    }
  723. X    time();
  724. X#if debug
  725. X    printf("Effective write rate: ");
  726. X#endif
  727. X    i = now.millitm - then.millitm;
  728. X    t = (now.time - then.time)*1000 + i;
  729. X    if (t > 0) {
  730. X    xfer = nblock * sizeof(buf) * 1000 / t;
  731. X#if debug
  732. X    printf("%d bytes/sec\n", xfer);
  733. X#endif
  734. X    }
  735. X#if debug
  736. X    else
  737. X    printf(" -- too quick to time!\n");
  738. X#endif
  739. X#if awk
  740. X    fprintf(stderr, "%.2f", t > 0 ? (float)xfer/1024 : 0);
  741. X#endif
  742. X
  743. X    sync();
  744. X    sleep(5);
  745. X    sync();
  746. X    lseek(f, 0L, 0);
  747. X    time();
  748. X    for (i = 0; i < nblock; i++) {
  749. X    if (read(f, buf, sizeof(buf)) <= 0)
  750. X        perror("fstime: read");
  751. X    }
  752. X    time();
  753. X#if debug
  754. X    printf("Effective read rate: ");
  755. X#endif
  756. X    i = now.millitm - then.millitm;
  757. X    t = (now.time - then.time)*1000 + i;
  758. X    if (t > 0) {
  759. X    xfer = nblock * sizeof(buf) * 1000 / t;
  760. X#if debug
  761. X    printf("%d bytes/sec\n", xfer);
  762. X#endif
  763. X    }
  764. X#if debug
  765. X    else
  766. X    printf(" -- too quick to time!\n");
  767. X#endif
  768. X#if awk
  769. X    fprintf(stderr, " %.2f", t > 0 ? (float)xfer/1024 : 0);
  770. X#endif
  771. X
  772. X    sync();
  773. X    sleep(5);
  774. X    sync();
  775. X    lseek(f, 0L, 0);
  776. X    time();
  777. X    for (i = 0; i < nblock; i++) {
  778. X    if (read(f, buf, sizeof(buf)) <= 0)
  779. X        perror("fstime: read in copy");
  780. X    if (write(g, buf, sizeof(buf)) <= 0)
  781. X        perror("fstime: write in copy");
  782. X    }
  783. X    time();
  784. X#if debug
  785. X    printf("Effective copy rate: ");
  786. X#endif
  787. X    i = now.millitm - then.millitm;
  788. X    t = (now.time - then.time)*1000 + i;
  789. X    if (t > 0) {
  790. X    xfer = nblock * sizeof(buf) * 1000 / t;
  791. X#if debug
  792. X    printf("%d bytes/sec\n", xfer);
  793. X#endif
  794. X    }
  795. X#if debug
  796. X    else
  797. X    printf(" -- too quick to time!\n");
  798. X#endif
  799. X#if awk
  800. X    fprintf(stderr, " %.2f\n", t > 0 ? (float)xfer/1024 : 0);
  801. X#endif
  802. X
  803. X}
  804. End-of-File-Grunt
  805. if test 2868 -ne `cat 'cctest.c' | wc -c`
  806. then
  807.     echo 'shar: transmission error (expected 2868 characters)'
  808. fi
  809. echo 'x - check.sed'
  810. if test -f 'check.sed'
  811. then
  812.     echo 'shar: over-writing existing file check.sed'
  813. fi
  814. sed 's/^X//' > check.sed <<'End-of-File-Grunt'
  815. X# Note: undocumented sed feature, use # for comments $Header: check.sed,v 3.9 87/09/09 12:33:08 kenj Exp $
  816. X/^Tmp\/userlog\.[0-9]*:$/d
  817. X/^Tmp\/masterlog\.[0-9]*:$/d
  818. X/New Run/d
  819. X/^user [0-9][0-9]* master stream [0-9][0-9]* pid [0-9][0-9]* pipe fd [0-9][0-9]*/d
  820. X/^user [0-9][0-9]* clone [0-9][0-9]* stream [0-9][0-9]* pid [0-9][0-9]* pipe fd [0-9][0-9]*/d
  821. X/^master pid [0-9]*$/d
  822. X/^clone [0-9][0-9]* [0-9][0-9]* pid [0-9]*$/d
  823. X/^user [0-9][0-9]* pid [0-9][0-9]* done$/d
  824. X/^clone [0-9][0-9]* done, pid [0-9][0-9]* $/d
  825. Xs/ [0-9][0-9]*$//
  826. X/^ *$/d
  827. End-of-File-Grunt
  828. if test 535 -ne `cat 'check.sed' | wc -c`
  829. then
  830.     echo 'shar: transmission error (expected 535 characters)'
  831. fi
  832. echo 'x - cleanup'
  833. if test -f 'cleanup'
  834. then
  835.     echo 'shar: over-writing existing file cleanup'
  836. fi
  837. sed 's/^X//' > cleanup <<'End-of-File-Grunt'
  838. X#! /bin/sh
  839. X#
  840. X# $Header: cleanup,v 3.5 87/06/22 14:40:45 kjmcdonell Beta $
  841. X#
  842. X#  Cleanup when an iterative test terminates
  843. X#
  844. Xlog=Results/log
  845. Xwhile ( test $# -ge 1 )
  846. Xdo
  847. X    opt=$1
  848. X    shift
  849. X    case $opt
  850. X    in
  851. X
  852. X    -a)    : abort
  853. X    echo '' >>$log
  854. X    echo '**************************' >>$log
  855. X    echo '* Benchmark Aborted .... *' >>$log
  856. X    echo '**************************' >>$log
  857. X    echo 'Benchmark Aborted ....'
  858. X    echo  ; sleep 2 ; echo  ; sleep 2 ; echo 
  859. X    echo "" >>$log
  860. X    echo " " `who | wc -l` "interactive users." >>$log
  861. X    echo "" >>$log
  862. X    date=`date`
  863. X    echo "End Benchmark Run ($date) ...." >>$log
  864. X    echo "End Benchmark Run ($date) ...."
  865. X    ;;
  866. X
  867. X
  868. X    -f)    : filesystem throughput
  869. X    awk -f fs.awk <$1 >>$log
  870. X    rm -f $1
  871. X    shift
  872. X    ;;
  873. X    
  874. X    -i)    : report last iteration
  875. X    echo "Terminated during iteration $1" >>$log
  876. X    shift
  877. X    ;;
  878. X
  879. X    -l) : logfile
  880. X    log=$1
  881. X    shift
  882. X    ;;
  883. X    
  884. X    -r) : reason for failure
  885. X    echo $1
  886. X    echo $1 >>$log
  887. X    shift
  888. X    ;;
  889. X
  890. X    -m)    : mem throughput tests
  891. X    awk -f mem.awk <$1 >>$log
  892. X    rm -f $1
  893. X    shift
  894. X    ;;
  895. X
  896. X    -t)    : timing with /bin/time
  897. X    awk -f time.awk <$1 >>$log
  898. X    rm -f $1
  899. X    shift
  900. X    ;;
  901. X
  902. X    -w) : work - save information from multi-user test
  903. X    worktmp=Tmp/work.tmp
  904. X    for m in Tmp/masterlog.*
  905. X    do
  906. X        if ( test $m != "Tmp/masterlog.*" )
  907. X        then
  908. X        echo ${m}: >>$worktmp
  909. X        cat $m >>$worktmp
  910. X        echo "" >>$worktmp
  911. X        rm -f $m
  912. X        fi
  913. X    done
  914. X    for u in Tmp/userlog.*
  915. X    do
  916. X        if ( test $u != "Tmp/userlog.*" )
  917. X        then
  918. X        echo ${u}: >>$worktmp
  919. X        cat $u >>$worktmp
  920. X        echo "" >>$worktmp
  921. X        rm -f $u
  922. X        fi
  923. X    done
  924. X    PS1=`sh -ic "" 2>&1`
  925. X    sed -e "s/\\${PS1}//g" $worktmp | sed -f check.sed >loggederrs
  926. X    if ( test -s loggederrs )
  927. X    then
  928. X        echo "*************************************" >>$log
  929. X        echo "* Apparent errors from makework ... *" >>$log
  930. X        echo "*************************************" >>$log
  931. X        cat loggederrs >>$log
  932. X    fi
  933. X        rm -f loggederrs
  934. X    cat $worktmp >>${log}.work
  935. X    rm -f $worktmp
  936. X    ;;
  937. X
  938. X    '')    : 'skip it (residual effect of shifts)'
  939. X    ;;
  940. X
  941. X    *)
  942. X    echo "cleanup: bad option ($opt)" >>$log
  943. Xesac
  944. Xdone
  945. Xexit
  946. End-of-File-Grunt
  947. if test 2003 -ne `cat 'cleanup' | wc -c`
  948. then
  949.     echo 'shar: transmission error (expected 2003 characters)'
  950. fi
  951. echo 'x - clock.c'
  952. if test -f 'clock.c'
  953. then
  954.     echo 'shar: over-writing existing file clock.c'
  955. fi
  956. sed 's/^X//' > clock.c <<'End-of-File-Grunt'
  957. X/*
  958. X *  clock -- check alarm signal accuracy
  959. X *
  960. X *  $Header: clock.c,v 3.4 87/06/22 14:22:54 kjmcdonell Beta $
  961. X */
  962. X
  963. X#include <signal.h>
  964. X#include <stdio.h>
  965. X#include <sys/types.h>
  966. X#ifdef BSD4v1
  967. X#include <sys/timeb.h>
  968. X#endif
  969. X#ifdef BSD4v2
  970. X#include <sys/time.h>
  971. X#endif
  972. X#ifdef SysV
  973. X#include <sys/times.h>
  974. X#include <sys/param.h>
  975. X#ifdef interdata
  976. X#define HZ tbuffer.tms_cfreq
  977. X#endif
  978. X#ifndef HZ
  979. X    On your system, what is the value of HZ for high resolution elapsed
  980. X    time as returned by times() or its equivalent?
  981. X#endif
  982. X#endif
  983. X
  984. X#define GRANULE        5
  985. X#define NUM_ALRM    12
  986. X
  987. Xmain(argc, argv)
  988. Xint    argc;
  989. Xchar    *argv[];
  990. X{
  991. X    int            onalarm();
  992. X    register int    i = 0;
  993. X    int            expected;
  994. X    float        wallclock;
  995. X    long        then;
  996. X#ifdef SysV
  997. X    struct tms        tbuffer;
  998. X#endif
  999. X#ifdef BSD4v1
  1000. X    struct timeb    tbuf;
  1001. X    int            msec;
  1002. X#endif
  1003. X#ifdef BSD4v2
  1004. X    struct timeval    tval;
  1005. X    struct timezone    tzone;
  1006. X    long        usec;
  1007. X#endif
  1008. X
  1009. X#ifdef SysV
  1010. X    then = times(&tbuffer);
  1011. X#else
  1012. X#ifdef BSD4v1
  1013. X    ftime(&tbuf);
  1014. X    then = tbuf.time;
  1015. X    msec = tbuf.millitm;
  1016. X#else
  1017. X#ifdef BSD4v2
  1018. X    gettimeofday(&tval, &tzone);
  1019. X    then = tval.tv_sec;
  1020. X    usec = tval.tv_usec;
  1021. X#else
  1022. X    What sort of Unix system is this?
  1023. X#endif
  1024. X#endif
  1025. X#endif
  1026. X    while (i++ < NUM_ALRM) {
  1027. X        signal(SIGALRM, onalarm);
  1028. X        alarm(GRANULE);
  1029. X        pause();
  1030. X    }
  1031. X#ifdef SysV
  1032. X    wallclock = (times(&tbuffer) - then)/HZ;
  1033. X#endif
  1034. X#ifdef BSD4v1
  1035. X    ftime(&tbuf);
  1036. X    wallclock = tbuf.time - then + (float)(tbuf.millitm - msec)/1000;
  1037. X#endif
  1038. X#ifdef BSD4v2
  1039. X    gettimeofday(&tval, &tzone);
  1040. X    wallclock = tval.tv_sec - then + (float)(tval.tv_usec - usec)/1000000;
  1041. X#endif
  1042. X    expected = GRANULE * NUM_ALRM;
  1043. X    printf("%d x %d sec delays takes %.2f wallclock secs (error %.2f%%)\n",
  1044. X    NUM_ALRM, GRANULE, wallclock, 100.0*(float)(expected-wallclock)/expected);
  1045. X    exit(0);
  1046. X}
  1047. X
  1048. Xonalarm() { }
  1049. End-of-File-Grunt
  1050. if test 1807 -ne `cat 'clock.c' | wc -c`
  1051. then
  1052.     echo 'shar: transmission error (expected 1807 characters)'
  1053. fi
  1054. echo 'x - comptbl.1'
  1055. if test -f 'comptbl.1'
  1056. then
  1057.     echo 'shar: over-writing existing file comptbl.1'
  1058. fi
  1059. sed 's/^X//' > comptbl.1 <<'End-of-File-Grunt'
  1060. X.(b
  1061. X.TS
  1062. Xbox,center;
  1063. Xc s s s s
  1064. Xc | c s | c s
  1065. Xc | c | c | c | c
  1066. Xc | c | c | c | c
  1067. Xc | c | c | c | c
  1068. Xl | n | n | n | n.
  1069. XRaw Speed
  1070. X_
  1071. X    Absolute    Relative
  1072. X    _    _    _    _
  1073. X    Elapsed    CPU    Elapsed    CPU
  1074. XTest Description    Time    Time    Time    Time
  1075. X_
  1076. End-of-File-Grunt
  1077. if test 221 -ne `cat 'comptbl.1' | wc -c`
  1078. then
  1079.     echo 'shar: transmission error (expected 221 characters)'
  1080. fi
  1081. echo 'x - comptbl.2'
  1082. if test -f 'comptbl.2'
  1083. then
  1084.     echo 'shar: over-writing existing file comptbl.2'
  1085. fi
  1086. sed 's/^X//' > comptbl.2 <<'End-of-File-Grunt'
  1087. X.(b
  1088. X.TS
  1089. Xbox,center;
  1090. Xc s s s s.
  1091. XMemory Throughput
  1092. X(1000s integer accesses per sec.)
  1093. X_
  1094. X.T&
  1095. Xc | c s | c s
  1096. Xc | c s | c s
  1097. Xc | c | c | c | c
  1098. Xn | n | n | n | n.
  1099. X    Absolute    Relative
  1100. XArray Size    _    _
  1101. X(K bytes)    Sequential    Random    Sequential    Random
  1102. X_
  1103. End-of-File-Grunt
  1104. if test 236 -ne `cat 'comptbl.2' | wc -c`
  1105. then
  1106.     echo 'shar: transmission error (expected 236 characters)'
  1107. fi
  1108. echo 'x - comptbl.3'
  1109. if test -f 'comptbl.3'
  1110. then
  1111.     echo 'shar: over-writing existing file comptbl.3'
  1112. fi
  1113. sed 's/^X//' > comptbl.3 <<'End-of-File-Grunt'
  1114. X.(b
  1115. X.TS
  1116. Xbox,center;
  1117. Xc s s s s s s
  1118. Xc | c s s | c s s.
  1119. XFilesystem Throughput (Kchars per sec.)
  1120. X_
  1121. End-of-File-Grunt
  1122. if test 95 -ne `cat 'comptbl.3' | wc -c`
  1123. then
  1124.     echo 'shar: transmission error (expected 95 characters)'
  1125. fi
  1126. echo 'x - comptbl.4'
  1127. if test -f 'comptbl.4'
  1128. then
  1129.     echo 'shar: over-writing existing file comptbl.4'
  1130. fi
  1131. sed 's/^X//' > comptbl.4 <<'End-of-File-Grunt'
  1132. X_
  1133. X.T&
  1134. Xl | c s s | c s s
  1135. Xl | c | c | c | c | c | c
  1136. Xl | c | c | c | c | c | c
  1137. Xl | n | n | n | n | n | n.
  1138. X    Absolute    Relative
  1139. X    _    _    _    _    _    _
  1140. XFile Size    Write    Read    Copy    Write    Read    Copy
  1141. X_
  1142. End-of-File-Grunt
  1143. if test 179 -ne `cat 'comptbl.4' | wc -c`
  1144. then
  1145.     echo 'shar: transmission error (expected 179 characters)'
  1146. fi
  1147. echo 'x - comptbl.5'
  1148. if test -f 'comptbl.5'
  1149. then
  1150.     echo 'shar: over-writing existing file comptbl.5'
  1151. fi
  1152. sed 's/^X//' > comptbl.5 <<'End-of-File-Grunt'
  1153. X.(b
  1154. X.TS
  1155. Xbox,center;
  1156. Xc s s s s
  1157. Xc | c s | c s
  1158. Xc | c | c | c | c
  1159. Xc | c | c | c | c
  1160. Xn | n | n | n | n.
  1161. XSimulated Work Load
  1162. X_
  1163. X    Absolute    Relative
  1164. X    _    _    _    _
  1165. XUsers    Elapsed Time    CPU Time    Elapsed Time    CPU Time
  1166. X_
  1167. End-of-File-Grunt
  1168. if test 201 -ne `cat 'comptbl.5' | wc -c`
  1169. then
  1170.     echo 'shar: transmission error (expected 201 characters)'
  1171. fi
  1172. echo 'x - context1.c'
  1173. if test -f 'context1.c'
  1174. then
  1175.     echo 'shar: over-writing existing file context1.c'
  1176. fi
  1177. sed 's/^X//' > context1.c <<'End-of-File-Grunt'
  1178. X/*
  1179. X *  Context switching via synchronized unbuffered pipe i/o
  1180. X *
  1181. X *  $Header: context1.c,v 3.4 87/06/22 14:22:59 kjmcdonell Beta $
  1182. X */
  1183. X
  1184. Xmain(argc, argv)
  1185. Xint    argc;
  1186. Xchar    *argv[];
  1187. X{
  1188. X    int    check;
  1189. X    int    iter;
  1190. X    int    p1[2], p2[2];
  1191. X
  1192. X    if (argc != 2) {
  1193. X        printf("Usage: context count\n");
  1194. X        exit(1);
  1195. X    }
  1196. X
  1197. X    iter = atoi(argv[1]);
  1198. X    if (pipe(p1) || pipe(p2)) {
  1199. X        perror("pipe create failed");
  1200. X        exit(1);
  1201. X    }
  1202. X
  1203. X    if (fork()) {
  1204. X        /* master, write p1 & read p2 */
  1205. X        close(p1[0]); close(p2[1]);
  1206. X        while (iter > 0) {
  1207. X            if (write(p1[1], (char *)&iter, sizeof(iter)) != sizeof(iter)) {
  1208. X                perror("master write failed");
  1209. X                exit(1);
  1210. X            }
  1211. X            if (read(p2[0], (char *)&check, sizeof(check)) != sizeof(check)) {
  1212. X                perror("master read failed");
  1213. X                exit(1);
  1214. X            }
  1215. X            if (check != iter) {
  1216. X                printf("Master sync error: expect %d, got %d\n",
  1217. X                    iter, check);
  1218. X                exit(2);
  1219. X            }
  1220. X            iter--;
  1221. X        }
  1222. X    }
  1223. X    else {
  1224. X        /* slave, read p1 & write p2 */
  1225. X        close(p1[1]); close(p2[0]);
  1226. X        while (iter > 0) {
  1227. X            if (read(p1[0], (char *)&check, sizeof(check)) != sizeof(check)) {
  1228. X                perror("slave read failed");
  1229. X                exit(1);
  1230. X            }
  1231. X            if (check != iter) {
  1232. X                printf("Slave sync error: expect %d, got %d\n",
  1233. X                    iter, check);
  1234. X                exit(2);
  1235. X            }
  1236. X            if (write(p2[1], (char *)&iter, sizeof(iter)) != sizeof(check)) {
  1237. X                perror("slave write failed");
  1238. X                exit(1);
  1239. X            }
  1240. X            iter--;
  1241. X        }
  1242. X    }
  1243. X    exit(0);
  1244. X}
  1245. End-of-File-Grunt
  1246. if test 1344 -ne `cat 'context1.c' | wc -c`
  1247. then
  1248.     echo 'shar: transmission error (expected 1344 characters)'
  1249. fi
  1250. echo 'x - dc.dat'
  1251. if test -f 'dc.dat'
  1252. then
  1253.     echo 'shar: over-writing existing file dc.dat'
  1254. fi
  1255. sed 's/^X//' > dc.dat <<'End-of-File-Grunt'
  1256. X99
  1257. Xk
  1258. X2
  1259. Xv
  1260. Xp
  1261. Xq
  1262. X[ calculate the sqrt(2) to 99 decimal places ... John Lions Test ]
  1263. X[ $Header: dc.dat,v 1.1 87/06/22 14:28:28 kjmcdonell Beta $ ]
  1264. End-of-File-Grunt
  1265. if test 142 -ne `cat 'dc.dat' | wc -c`
  1266. then
  1267.     echo 'shar: transmission error (expected 142 characters)'
  1268. fi
  1269. echo 'x - dummy.c'
  1270. if test -f 'dummy.c'
  1271. then
  1272.     echo 'shar: over-writing existing file dummy.c'
  1273. fi
  1274. sed 's/^X//' > dummy.c <<'End-of-File-Grunt'
  1275. X/*
  1276. X *  Hacked up C program for use in the standard shell.? scripts of
  1277. X *  the multiuser test.  This is based upon makework.c, and is typically
  1278. X *  edited using edscript.2 before compilation.
  1279. X *
  1280. X * $Header: dummy.c,v 3.4 87/06/23 15:54:53 kjmcdonell Beta $
  1281. X */
  1282. X
  1283. X#include <stdio.h>
  1284. X#include <signal.h>
  1285. X
  1286. X#define DEF_RATE    5.0
  1287. X#define GRANULE        5
  1288. X#define CHUNK        60
  1289. X#define MAXCHILD    12
  1290. X#define MAXWORK        10
  1291. X
  1292. Xfloat    thres;
  1293. Xfloat    est_rate = DEF_RATE;
  1294. Xint    nusers;        /* number of concurrent users to be simulated by
  1295. X             * this process */
  1296. Xint    firstuser;    /* ordinal identification of first user for this
  1297. X             * process */
  1298. Xint    nwork = 0;    /* number of job streams */
  1299. Xint    exit_status = 0;    /* returned to parent */
  1300. Xint    sigpipe;    /* pipe write error flag */
  1301. X
  1302. Xstruct st_work {
  1303. X    char    *cmd;        /* name of command to run */
  1304. X    char    **av;        /* arguments to command */
  1305. X    char    *input;        /* standard input buffer */
  1306. X    int    inpsize;    /* size of standard input buffer */
  1307. X} work[MAXWORK];
  1308. X
  1309. Xstruct {
  1310. X    int    xmit;    /* # characters sent */
  1311. X    char    *bp;    /* std input buffer pointer */
  1312. X    int    blen;    /* std input buffer length */
  1313. X    int    fd;    /* stdin to command */
  1314. X    int    pid;    /* child PID */
  1315. X    char    *line;    /* start of input line */ 
  1316. X    int    firstjob;    /* inital piece of work */
  1317. X    int    thisjob;    /* current piece of work */
  1318. X} child[MAXCHILD], *cp;
  1319. X
  1320. Xmain(argc, argv)
  1321. Xint    argc;
  1322. Xchar    *argv[];
  1323. X{
  1324. X    int        i;
  1325. X    int        l;
  1326. X    int        fcopy = 0;    /* fd for copy output */
  1327. X    int        master = 1;    /* the REAL master, == 0 for clones */
  1328. X    int        nchild;        /* no. of children for a clone to run */
  1329. X    int        done;        /* count of children finished */
  1330. X    int        output;        /* aggregate output char count for all
  1331. X                   children */
  1332. X    int        c;
  1333. X    int        thiswork = 0;    /* next job stream to allocate */
  1334. X    int        nch;        /* # characters to write */
  1335. X    int        written;    /* # characters actully written */
  1336. X    char    logname[15];    /* name of the log file(s) */
  1337. X    int        onalarm();
  1338. X    int        pipeerr();
  1339. X    int        wrapup();
  1340. X    int        grunt();
  1341. X    char    *malloc();
  1342. X    int        pvec[2];    /* for pipes */
  1343. X    char    *p;
  1344. X    char    *prog;        /* my name */
  1345. X
  1346. X#if ! debug
  1347. X    freopen("masterlog.00", "a", stderr);
  1348. X#endif
  1349. X    fprintf(stderr, "*** New Run ***  ");
  1350. X    prog = argv[0];
  1351. X    while (argc > 1 && argv[1][0] == '-')  {
  1352. X    p = &argv[1][1];
  1353. X    argc--;
  1354. X    argv++;
  1355. X    while (*p) {
  1356. X        switch (*p) {
  1357. X        case 'r':
  1358. X            /* code DELETED here */
  1359. X            argc--;
  1360. X            argv++;
  1361. X            break;
  1362. X
  1363. X        case 'c':
  1364. X            /* code DELETED here */
  1365. X            lseek(fcopy, 0L, 2);    /* append at end of file */
  1366. X            break;
  1367. X
  1368. X        default:
  1369. X        fprintf(stderr, "%s: bad flag '%c'\n", prog, *p);
  1370. X            exit(4);
  1371. X        }
  1372. X        p++;
  1373. X    }
  1374. X    }
  1375. X    
  1376. X    if (argc < 2) {
  1377. X    fprintf(stderr, "%s: missing nusers\n", prog);
  1378. X    exit(4);
  1379. X    }
  1380. X
  1381. X    nusers = atoi(argv[1]);
  1382. X    if (nusers < 1) {
  1383. X    fprintf(stderr, "%s: impossible nusers (%d<-%s)\n", prog, nusers, argv[1]);
  1384. X    exit(4);
  1385. X    }
  1386. X    fprintf(stderr, "%d Users\n", nusers);
  1387. X    argc--;
  1388. X    argv++;
  1389. X
  1390. X    /* build job streams */
  1391. X    getwork();
  1392. X#if debug
  1393. X    dumpwork();
  1394. X#endif
  1395. X
  1396. X    /* clone copies of myself to run up to MAXCHILD jobs each */
  1397. X    firstuser = MAXCHILD;
  1398. X    fprintf(stderr, "master pid %d\n", getpid());
  1399. X    fflush(stderr);
  1400. X    while (nusers > MAXCHILD) {
  1401. X    fflush(stderr);
  1402. X    if (nusers >= 2*MAXCHILD)
  1403. X        /* the next clone must run MAXCHILD jobs */
  1404. X        nchild = MAXCHILD;
  1405. X    else
  1406. X        /* the next clone must run the leftover jobs */
  1407. X        nchild = nusers - MAXCHILD;
  1408. X    if ((l = fork()) == -1) {
  1409. X        /* fork failed */
  1410. X        fatal("** clone fork failed **\n");
  1411. X        goto bepatient;
  1412. X    } else if (l > 0) {
  1413. X        fprintf(stderr, "master clone pid %d\n", l);
  1414. X        /* I am the master with nchild fewer jobs to run */
  1415. X        nusers -= nchild;
  1416. X        firstuser += MAXCHILD;
  1417. X        continue;
  1418. X    } else {
  1419. X        /* I am a clone, run MAXCHILD jobs */
  1420. X#if ! debug
  1421. X        sprintf(logname, "masterlog.%02d", firstuser/MAXCHILD);
  1422. X        freopen(logname, "w", stderr);
  1423. X#endif
  1424. X        master = 0;
  1425. X        nusers = nchild;
  1426. X        break;
  1427. X    }
  1428. X    }
  1429. X    if (master)
  1430. X    firstuser = 0;
  1431. X
  1432. X    close(0);
  1433. X
  1434. X    /* code DELETED here */
  1435. X
  1436. X    fflush(stderr);
  1437. X
  1438. X    srand(time(0));
  1439. X    thres = 0;
  1440. X    done = output = 0;
  1441. X    for (i = 0; i < nusers; i++) {
  1442. X    if (child[i].blen == 0)
  1443. X        done++;
  1444. X    else
  1445. X        thres += est_rate * GRANULE;
  1446. X    }
  1447. X    est_rate = thres;
  1448. X
  1449. X    signal(SIGALRM, onalarm);
  1450. X    signal(SIGPIPE, pipeerr);
  1451. X    alarm(GRANULE);
  1452. X    while (done < nusers) {
  1453. X    for (i = 0; i < nusers; i++) {
  1454. X        cp = &child[i];
  1455. X        if (cp->xmit >= cp->blen) continue;
  1456. X        l = rand() % CHUNK + 1;    /* 1-CHUNK chars */
  1457. X        if (l == 0) continue;
  1458. X        if (cp->xmit + l > cp->blen)
  1459. X        l = cp->blen - cp->xmit;
  1460. X        p = cp->bp;
  1461. X        cp->bp += l;
  1462. X        cp->xmit += l;
  1463. X#if debug
  1464. X        fprintf(stderr, "child %d, %d processed, %d to go\n", i, cp->xmit, cp->blen - cp->xmit);
  1465. X#endif
  1466. X        while (p < cp->bp) {
  1467. X        if (*p == '\n' || (p == &cp->bp[-1] && cp->xmit >= cp->blen)) {
  1468. X            /* write it out */
  1469. X            nch = p - cp->line + 1;
  1470. X            if ((written = write(cp->fd, cp->line, nch)) != nch) {
  1471. X
  1472. X            /* code DELETED here */
  1473. X
  1474. X            }
  1475. X            if (fcopy)
  1476. X            write(fcopy, cp->line, p - cp->line + 1);
  1477. X#if debug
  1478. X            fprintf(stderr, "child %d gets \"", i);
  1479. X            {
  1480. X            char *q = cp->line;
  1481. X            while (q <= p) {
  1482. X                if (*q >= ' ' && *q <= '~')
  1483. X                    fputc(*q, stderr);
  1484. X                else
  1485. X                    fprintf(stderr, "\\%03o", *q);
  1486. X                q++;
  1487. X            }
  1488. X            }
  1489. X            fputc('"', stderr);
  1490. X#endif
  1491. X            cp->line = &p[1];
  1492. X        }
  1493. X        p++;
  1494. X        }
  1495. X        if (cp->xmit >= cp->blen) {
  1496. X        done++;
  1497. X        close(cp->fd);
  1498. X#if debug
  1499. X    fprintf(stderr, "child %d, close std input\n", i);
  1500. X#endif
  1501. X        }
  1502. X        output += l;
  1503. X    }
  1504. X    while (output > thres) {
  1505. X        pause();
  1506. X#if debug
  1507. X        fprintf(stderr, "after pause: output, thres, done %d %.2f %d\n", output, thres, done);
  1508. X#endif
  1509. X    }
  1510. X    }
  1511. X
  1512. Xbepatient:
  1513. X    alarm(0);
  1514. X/****
  1515. X *  If everything is going OK, we should simply be able to keep
  1516. X *  looping unitil 'wait' fails, however some descendent process may
  1517. X *  be in a state from which it can never exit, and so a timeout
  1518. X *  is used.
  1519. X *  5 minutes should be ample, since the time to run all jobs is of
  1520. X *  the order of 5-10 minutes, however some machines are painfully slow,
  1521. X *  so the timeout has been set at 20 minutes (1200 seconds).
  1522. X ****/
  1523. X
  1524. X    /* code DELETED here */
  1525. X
  1526. X}
  1527. X
  1528. Xonalarm()
  1529. X{
  1530. X    thres += est_rate;
  1531. X    signal(SIGALRM, onalarm);
  1532. X    alarm(GRANULE);
  1533. X}
  1534. X
  1535. Xgrunt()
  1536. X{
  1537. X    /* timeout after label "bepatient" in main */
  1538. X    exit_status = 4;
  1539. X    wrapup();
  1540. X}
  1541. X
  1542. Xpipeerr()
  1543. X{
  1544. X    sigpipe++;
  1545. X}
  1546. X
  1547. Xwrapup()
  1548. X{
  1549. X    /* DUMMY, real code dropped */
  1550. X}
  1551. X
  1552. Xgetwork()
  1553. X{
  1554. X
  1555. X    /* DUMMY, real code dropped */
  1556. X    gets();
  1557. X    strncpy();
  1558. X    malloc(); realloc();
  1559. X    open(); close();
  1560. X}
  1561. X
  1562. Xfatal(s)
  1563. Xchar *s;
  1564. X{
  1565. X    int    i;
  1566. X    fprintf(stderr, s);
  1567. X    fflush(stderr);
  1568. X    perror("Reason?");
  1569. X    for (i = 0; i < nusers; i++) {
  1570. X    if (child[i].pid > 0 && kill(child[i].pid, SIGKILL) != -1)
  1571. X        fprintf(stderr, "pid %d killed off\n", child[i].pid);
  1572. X    }
  1573. X    fflush(stderr);
  1574. X    exit_status = 4;
  1575. X    return;
  1576. X}
  1577. End-of-File-Grunt
  1578. if test 6780 -ne `cat 'dummy.c' | wc -c`
  1579. then
  1580.     echo 'shar: transmission error (expected 6780 characters)'
  1581. fi
  1582. echo 'x - edit.dat'
  1583. if test -f 'edit.dat'
  1584. then
  1585.     echo 'shar: over-writing existing file edit.dat'
  1586. fi
  1587. sed 's/^X//' > edit.dat <<'End-of-File-Grunt'
  1588. X/*
  1589. X *  COBBLED program - test for editing
  1590. X *
  1591. X *  edit [ chars_per_sec ]
  1592. X *
  1593. X *  $Header: edit.dat,v 3.3 86/01/30 07:53:17 kenj Beta $
  1594. X */
  1595. X
  1596. X#include <stdio.h>
  1597. X#include <signal.h>
  1598. X
  1599. X#define MEAN    5
  1600. X#define GRANULE    5
  1601. X
  1602. Xint    thres;
  1603. Xint    est_mean = MEAN;
  1604. X
  1605. Xmain(argc, argv)
  1606. Xint    argc;
  1607. Xchar    *argv[];
  1608. X{
  1609. X    int    onalarm();
  1610. X
  1611. X    if (argc == 2) {
  1612. X        est_mean = atoi(argv[1]);
  1613. X        if (est_mean <= 0) {
  1614. X            fprintf(stderr, "edit: bad mean, reset to %d chars/sec\n", MEAN);
  1615. X            est_mean = MEAN;
  1616. X        }
  1617. X    }
  1618. X
  1619. X/**
  1620. X ** BEGIN BLOCK OF INSERTED TEXT TO BOOST FILE SIZE
  1621. XThis is some text which has been added to the middle of
  1622. Xthe file to increase the file size to the point where it is realistic.
  1623. X
  1624. XHow 'bout some random pascal code?
  1625. X
  1626. Xprogram elcheapo(input, output);
  1627. X
  1628. Xconst
  1629. X    DISPSIZE = 10;    { display is DISPSIZE characters long }
  1630. X    SIGN = 1;        { sign at display[SIGN] }
  1631. X    NSTART = 2;        { number starts is display[NSTART] }
  1632. X    NEND = 9;        { . and ends at display[NEND] }
  1633. X    ERRFLAG = 10;    { error flag display[ERFLAG] }
  1634. X
  1635. Xtype
  1636. X    st = (OK, ERROR);
  1637. X    vt = (INTEGER, REAL);
  1638. X    key = (DOT,PLUS,MINUS,DIV,MULT,EQUAL,ON,OFF,CLEAR,NEG,noop);
  1639. X    number = record value: real;
  1640. X            scale: integer;
  1641. X            vtype: vt;
  1642. X         end;
  1643. X
  1644. Xvar
  1645. X    r, m: number;
  1646. X    ukey: integer;
  1647. X    code, lastop: key;
  1648. X    done: boolean;
  1649. X    state: st;
  1650. X    disp: array [1..DISPSIZE] of char;
  1651. X
  1652. Xfunction power(base, n: integer): integer;
  1653. Xvar i, value: integer;
  1654. Xbegin
  1655. X    value := 1;
  1656. X    for i := 1 to n do value := value * base;
  1657. X    power := value
  1658. Xend; { power }
  1659. X
  1660. Xprocedure getkey(var code: integer);
  1661. Xvar c: char;
  1662. Xbegin
  1663. X    read(c);
  1664. X    if (c >= '0') and (c <= '9') then code := ord(c) - ord('0')
  1665. X    else
  1666. X    begin   if c = '.' then code := 10
  1667. X        else if c = '+' then code := 11
  1668. X        else if c = '-' then code := 12
  1669. X        else if c = '/' then code := 13
  1670. X        else if c = '*' then code := 14
  1671. X        else if c = '=' then code := 15
  1672. X        else if c = 'c' then code := 18
  1673. X        else if c = 'n' then code := 19
  1674. X        else if c = 'o' then
  1675. X        begin   read(c);
  1676. X            if c = 'n' then code := 16
  1677. X            else code := 17
  1678. X        end
  1679. X        else code := 20
  1680. X    end;
  1681. X    readln
  1682. Xend; { getkey }
  1683. X
  1684. Xfunction mapkey(code: integer): key;
  1685. Xbegin
  1686. X    if code = 10 then mapkey := DOT
  1687. X    else if code = 11 then mapkey := PLUS
  1688. X    else if code = 12 then mapkey := MINUS
  1689. X    else if code = 13 then mapkey := DIV
  1690. X    else if code = 14 then mapkey := MULT
  1691. X    else if code = 15 then mapkey := EQUAL
  1692. X    else if code = 16 then mapkey := ON
  1693. X    else if code = 17 then mapkey := OFF
  1694. X    else if code = 18 then mapkey := CLEAR
  1695. X    else if code = 19 then mapkey := NEG
  1696. X    else mapkey := noop
  1697. Xend; { mapkey }
  1698. X
  1699. X
  1700. Xbegin
  1701. X    done := false;
  1702. X    state := ERROR;
  1703. X    while not done do
  1704. X    begin   getkey(ukey);
  1705. X        code := mapkey(ukey);
  1706. X        if (code = ON) or (code = CLEAR) then
  1707. X        begin clear(m);
  1708. X          clear(r);
  1709. X          state := OK;
  1710. X          lastop := noop;
  1711. X          display(r)
  1712. X        end
  1713. X        else if code = OFF then done := true
  1714. X        else if state = OK then
  1715. X        begin   if (ukey >= 0) and (ukey <= 9) then
  1716. X            begin   if r.vtype = INTEGER then r.value := r.value*10 + ukey
  1717. X                else
  1718. X                begin   r.scale := r.scale + 1;
  1719. X                    r.value := r.value + ukey / power(10, r.scale)
  1720. X                end;
  1721. X                display(r);
  1722. X                if lastop = EQUAL then lastop := noop
  1723. X            end
  1724. X            else if (code = PLUS) or (code = MINUS) or (code = MULT) or
  1725. X                (code = DIV) then
  1726. X            begin if lastop = noop then m := r
  1727. X              else if lastop <> EQUAL then
  1728. X              begin eval(m, r, lastop);
  1729. X                display(m)
  1730. X              end;
  1731. X              clear(r);
  1732. X              lastop := code
  1733. X            end
  1734. X            else case code of
  1735. X            DOT:
  1736. X            begin if r.vtype = REAL then state := ERROR
  1737. X                  else r.vtype := REAL;
  1738. X                  display(r)
  1739. X            end;
  1740. X            EQUAL:
  1741. X            begin if (lastop <> noop) and (lastop <> EQUAL) then
  1742. X                  begin eval(m, r, lastop);
  1743. X                        display(m)
  1744. X                  end;    
  1745. X                  clear(r);
  1746. X                  lastop := EQUAL
  1747. X            end;
  1748. X            NEG:
  1749. X            begin r.value := -r.value;
  1750. X                  display(r)
  1751. X            end;
  1752. X        end { of case }
  1753. X          end { of else }
  1754. X    end { of while }
  1755. Xend.
  1756. X ** END BLOCK OF INSERTED TEXT TO BOOST FILE SIZE
  1757. X **/
  1758. X
  1759. X    /* (busy) wait for lock file ... */
  1760. X    while ((f = open("lock", 0)) < 0) sleep(3);
  1761. X    close(f);
  1762. X    signal(SIGALRM, onalarm);
  1763. X    alarm(GRANULE);
  1764. X    while (read(0, &c, 1) == 1) {
  1765. X        if (i % 20 == 0 && thres - i > est_mean * GRANULE)
  1766. X            sleep(rand() & 0x3);
  1767. X        write(1, &c, 1);
  1768. X        write(2, &c, 1);    /* copy onto std error */
  1769. X        i++;
  1770. X        if (i > thres) {
  1771. X            pause();
  1772. X        }
  1773. X    }
  1774. X}
  1775. XFiller to make 200 lines & 4500 bytes.
  1776. XThis
  1777. Xis
  1778. Xso
  1779. Xboring
  1780. Xyou
  1781. Xwouldn't
  1782. Xbelieve it.
  1783. X
  1784. Xonalarm()
  1785. X{
  1786. X    thres += est_rate;
  1787. X    signal(SIGALRM, onalarm);
  1788. X    alarm(GRANULE);
  1789. X}
  1790. End-of-File-Grunt
  1791. if test 4561 -ne `cat 'edit.dat' | wc -c`
  1792. then
  1793.     echo 'shar: transmission error (expected 4561 characters)'
  1794. fi
  1795. echo 'x - edscr1.dat'
  1796. if test -f 'edscr1.dat'
  1797. then
  1798.     echo 'shar: over-writing existing file edscr1.dat'
  1799. fi
  1800. sed 's/^X//' > edscr1.dat <<'End-of-File-Grunt'
  1801. X/alarm/
  1802. X//
  1803. X//
  1804. X//
  1805. X-10,.p
  1806. Xg/signal/s//burk/gp
  1807. X?alarm?
  1808. X.,$m0
  1809. X1
  1810. X/^}/
  1811. X1,.m$
  1812. X1,10p
  1813. X5
  1814. Xka
  1815. Xa
  1816. XThis is some inserted text.
  1817. X        and about another 4 or 5 lines
  1818. X        to go in here
  1819. X        for (i = 0; i < 10; i++) {
  1820. X            this is some code
  1821. X            in a loop;
  1822. X        }
  1823. X        printf("what rubbish, and fun .....\n");
  1824. X        Oh how boring.
  1825. X.
  1826. X1,.p
  1827. X'a+,.d
  1828. X1,$s/burk/signal/g
  1829. Xw temporary
  1830. Xq
  1831. End-of-File-Grunt
  1832. if test 339 -ne `cat 'edscr1.dat' | wc -c`
  1833. then
  1834.     echo 'shar: transmission error (expected 339 characters)'
  1835. fi
  1836. echo 'x - edscr2.dat'
  1837. if test -f 'edscr2.dat'
  1838. then
  1839.     echo 'shar: over-writing existing file edscr2.dat'
  1840. fi
  1841. sed 's/^X//' > edscr2.dat <<'End-of-File-Grunt'
  1842. X1,$s/[     ][     ]*$//
  1843. X1,20m80
  1844. X81,90m0
  1845. Xg/n[^k]*k/s//burk/g
  1846. X91,100m10
  1847. Xw grunt.c
  1848. Xq
  1849. End-of-File-Grunt
  1850. if test 76 -ne `cat 'edscr2.dat' | wc -c`
  1851. then
  1852.     echo 'shar: transmission error (expected 76 characters)'
  1853. fi
  1854. echo 'x - execl.c'
  1855. if test -f 'execl.c'
  1856. then
  1857.     echo 'shar: over-writing existing file execl.c'
  1858. fi
  1859. sed 's/^X//' > execl.c <<'End-of-File-Grunt'
  1860. X/*
  1861. X *  Execing
  1862. X *
  1863. X *  $Header: execl.c,v 3.5 87/06/22 15:37:08 kjmcdonell Beta $
  1864. X */
  1865. X
  1866. Xchar    bss[8*1024];    /* something worthwhile */
  1867. X
  1868. X#define main dummy
  1869. X            /* some reasonable code etc. */
  1870. X#include "big.c"
  1871. X
  1872. X#undef main
  1873. X
  1874. Xmain(argc, argv)    /* the real program */
  1875. Xint    argc;
  1876. Xchar    *argv[];
  1877. X{
  1878. X    int    iter;
  1879. X    char    count[6];
  1880. X
  1881. X    if (argc != 2) {
  1882. X        printf("Usage: %s count\n", argv[0]);
  1883. X        exit(1);
  1884. X    }
  1885. X
  1886. X    iter = atoi(argv[1]);
  1887. X
  1888. X    if (iter) {
  1889. X        sprintf(count, "%d", --iter);
  1890. X        execl("./execl", "execl", count, 0);
  1891. X        printf("Exec failed at iteration %d\n", iter);
  1892. X        perror("Reason");
  1893. X        exit(1);
  1894. X    }
  1895. X    exit(0);
  1896. X}
  1897. End-of-File-Grunt
  1898. if test 587 -ne `cat 'execl.c' | wc -c`
  1899. then
  1900.     echo 'shar: transmission error (expected 587 characters)'
  1901. fi
  1902. echo 'x - fs.awk'
  1903. if test -f 'fs.awk'
  1904. then
  1905.     echo 'shar: over-writing existing file fs.awk'
  1906. fi
  1907. sed 's/^X//' > fs.awk <<'End-of-File-Grunt'
  1908. X# $Header: fs.awk,v 3.4 87/06/22 14:27:32 kjmcdonell Beta $
  1909. X/real/    { next }
  1910. X/^[0-9][ .0-9]*$/ && NF==3 {
  1911. X    if (!fail) {
  1912. X        w+=$1; w2+=$1*$1; r+=$2; r2+=$2*$2; c+=$3; c2+=$3*$3; ok++
  1913. X    }
  1914. X    fail=0; iter++; next
  1915. X    }
  1916. X    { print "** Iteration ",iter+1," Failed: ",$0; fail=1; }
  1917. XEND {
  1918. X    if (fail) iter++
  1919. X    if (ok != iter) {
  1920. X        printf "For %d successful iterations from %d attempts ...\n",ok,iter
  1921. X        iter=ok
  1922. X    }
  1923. X    if (iter > 0) {
  1924. X        printf "Write: %.1f Kbytes per second  ",w/iter
  1925. X        if (iter > 1) printf " (variance %.1f)",(w2-2*w*w/iter+w*w/iter)/(iter-1)
  1926. X        printf "\nRead:  %.1f Kbytes per second  ",r/iter
  1927. X        if (iter > 1) printf " (variance %.1f)",(r2-2*r*r/iter+r*r/iter)/(iter-1)
  1928. X        printf "\nCopy:  %.1f Kbytes per second  ",c/iter
  1929. X        if (iter > 1) printf " (variance %.1f)",(c2-2*c*c/iter+c*c/iter)/(iter-1)
  1930. X        print
  1931. X    } else {
  1932. X        print "Write: -- no measured results!!"
  1933. X        print "Read: -- no measured results!!"
  1934. X        print "Copy: -- no measured results!!"
  1935. X    }
  1936. X    }
  1937. End-of-File-Grunt
  1938. if test 988 -ne `cat 'fs.awk' | wc -c`
  1939. then
  1940.     echo 'shar: transmission error (expected 988 characters)'
  1941. fi
  1942. echo 'x - fstime.c'
  1943. if test -f 'fstime.c'
  1944. then
  1945.     echo 'shar: over-writing existing file fstime.c'
  1946. fi
  1947. sed 's/^X//' > fstime.c <<'End-of-File-Grunt'
  1948. X/*
  1949. X * $Header: fstime.c,v 3.4 87/06/22 14:23:05 kjmcdonell Beta $
  1950. X */
  1951. X
  1952. X#include <stdio.h>
  1953. X#include <sys/types.h>
  1954. X#ifdef SysV
  1955. X#include <sys/times.h>
  1956. X#include <sys/param.h>
  1957. X#ifdef interdata
  1958. X#define HZ tbuffer.tms_cfreq
  1959. X#endif
  1960. X#ifndef HZ
  1961. X    On your system, what is the value of HZ for high resolution elapsed
  1962. X    time as returned by times() or its equivalent?
  1963. X#endif
  1964. X#endif
  1965. X#ifdef BSD4v1
  1966. X#include <sys/timeb.h>
  1967. X#endif
  1968. X#ifdef BSD4v2
  1969. X#include <sys/time.h>
  1970. X#endif
  1971. X#define NKBYTE 20
  1972. Xchar buf[BUFSIZ];
  1973. X
  1974. Xmain(argc, argv)
  1975. Xchar **argv;
  1976. X{
  1977. X    int            n = NKBYTE;
  1978. X    int            nblock;
  1979. X    int            f;
  1980. X    int            g;
  1981. X    int            i;
  1982. X    int            xfer, t;
  1983. X    long        then;
  1984. X#ifdef BSD4v1
  1985. X    struct timeb    tbuf;
  1986. X    int            msec;
  1987. X#endif
  1988. X#ifdef BSD4v2
  1989. X    struct timeval    tval;
  1990. X    struct timezone    tzone;
  1991. X    long        usec;
  1992. X#endif
  1993. X#ifdef SysV
  1994. X    struct tms        tbuffer;
  1995. X#endif
  1996. X
  1997. X    if (argc > 1)
  1998. X    n = atoi(argv[1]);
  1999. X#if debug
  2000. X    printf("File size: %d Kbytes\n", n);
  2001. X#endif
  2002. X    nblock = (n * 1024) / BUFSIZ;
  2003. X
  2004. X    if (argc == 3 && chdir(argv[2]) != -1) {
  2005. X#if debug
  2006. X    printf("Create files in directory: %s\n", argv[2]);
  2007. X#endif
  2008. X    }
  2009. X    close(creat("dummy0", 0600));
  2010. X    close(creat("dummy1", 0600));
  2011. X    f = open("dummy0", 2);
  2012. X    g = open("dummy1", 2);
  2013. X    unlink("dummy0");
  2014. X    unlink("dummy1");
  2015. X    for (i = 0; i < sizeof(buf); i++)
  2016. X    buf[i] = i & 0177;
  2017. X
  2018. X#ifdef SysV
  2019. X    then = times(&tbuffer);
  2020. X#else
  2021. X#ifdef BSD4v1
  2022. X    ftime(&tbuf);
  2023. X    then = tbuf.time;
  2024. X    msec = tbuf.millitm;
  2025. X#else
  2026. X#ifdef BSD4v2
  2027. X    gettimeofday(&tval, &tzone);
  2028. X    then = tval.tv_sec;
  2029. X    usec = tval.tv_usec;
  2030. X#else
  2031. X    What sort of Unix system if this?
  2032. X#endif
  2033. X#endif
  2034. X#endif
  2035. X    for (i = 0; i < nblock; i++) {
  2036. X    if (write(f, buf, sizeof(buf)) <= 0)
  2037. X        perror("fstime: write");
  2038. X    }
  2039. X#ifdef SysV
  2040. X    t = 1000*(times(&tbuffer) - then)/HZ;
  2041. X#endif
  2042. X#ifdef BSD4v1
  2043. X    ftime(&tbuf);
  2044. X    t = (tbuf.time - then)*1000 + tbuf.millitm - msec;
  2045. X#endif
  2046. X#ifdef BSD4v2
  2047. X    gettimeofday(&tval, &tzone);
  2048. X    t = (tval.tv_sec - then)*1000 + (tval.tv_usec - usec)/1000;
  2049. X#endif
  2050. X#if debug
  2051. X    printf("Effective write rate: ");
  2052. X#endif
  2053. X    if (t > 0) {
  2054. X    xfer = nblock * sizeof(buf) * 1000 / t;
  2055. X#if debug
  2056. X    printf("%d bytes/sec\n", xfer);
  2057. X#endif
  2058. X    }
  2059. X#if debug
  2060. X    else
  2061. X    printf(" -- too quick to time!\n");
  2062. X#endif
  2063. X#if awk
  2064. X    fprintf(stderr, "%.2f", t > 0 ? (float)xfer/1024 : 0);
  2065. X#endif
  2066. X
  2067. X    sync();
  2068. X    sleep(5);
  2069. X    sync();
  2070. X    lseek(f, 0L, 0);
  2071. X#ifdef SysV
  2072. X    then = times(&tbuffer);
  2073. X#endif
  2074. X#ifdef BSD4v1
  2075. X    times(&tbuf);
  2076. X    then = tbuf.time;
  2077. X    msec = tbuf.millitm;
  2078. X#endif
  2079. X#ifdef BSD4v2
  2080. X    gettimeofday(&tval, &tzone);
  2081. X    then = tval.tv_sec;
  2082. X    usec = tval.tv_usec;
  2083. X#endif
  2084. X    for (i = 0; i < nblock; i++) {
  2085. X    if (read(f, buf, sizeof(buf)) <= 0)
  2086. X        perror("fstime: read");
  2087. X    }
  2088. X#ifdef SysV
  2089. X    t = 1000*(times(&tbuffer) - then)/HZ;
  2090. X#endif
  2091. X#ifdef BSD4v1
  2092. X    ftime(&tbuf);
  2093. X    t = (tbuf.time - then)*1000 + tbuf.millitm - msec;
  2094. X#endif
  2095. X#ifdef BSD4v2
  2096. X    gettimeofday(&tval, &tzone);
  2097. X    t = (tval.tv_sec - then)*1000 + (tval.tv_usec - usec)/1000;
  2098. X#endif
  2099. X#if debug
  2100. X    printf("Effective read rate: ");
  2101. X#endif
  2102. X    if (t > 0) {
  2103. X    xfer = nblock * sizeof(buf) * 1000 / t;
  2104. X#if debug
  2105. X    printf("%d bytes/sec\n", xfer);
  2106. X#endif
  2107. X    }
  2108. X#if debug
  2109. X    else
  2110. X    printf(" -- too quick to time!\n");
  2111. X#endif
  2112. X#if awk
  2113. X    fprintf(stderr, " %.2f", t > 0 ? (float)xfer/1024 : 0);
  2114. X#endif
  2115. X
  2116. X    sync();
  2117. X    sleep(5);
  2118. X    sync();
  2119. X    lseek(f, 0L, 0);
  2120. X#ifdef SysV
  2121. X    then = times(&tbuffer);
  2122. X#endif
  2123. X#ifdef BSD4v1
  2124. X    times(&tbuf);
  2125. X    then = tbuf.time;
  2126. X    msec = tbuf.millitm;
  2127. X#endif
  2128. X#ifdef BSD4v2
  2129. X    gettimeofday(&tval, &tzone);
  2130. X    then = tval.tv_sec;
  2131. X    usec = tval.tv_usec;
  2132. X#endif
  2133. X    for (i = 0; i < nblock; i++) {
  2134. X    if (read(f, buf, sizeof(buf)) <= 0)
  2135. X        perror("fstime: read in copy");
  2136. X    if (write(g, buf, sizeof(buf)) <= 0)
  2137. X        perror("fstime: write in copy");
  2138. X    }
  2139. X#ifdef SysV
  2140. X    t = 1000*(times(&tbuffer) - then)/HZ;
  2141. X#endif
  2142. X#ifdef BSD4v1
  2143. X    ftime(&tbuf);
  2144. X    t = (tbuf.time - then)*1000 + tbuf.millitm - msec;
  2145. X#endif
  2146. X#ifdef BSD4v2
  2147. X    gettimeofday(&tval, &tzone);
  2148. X    t = (tval.tv_sec - then)*1000 + (tval.tv_usec - usec)/1000;
  2149. X#endif
  2150. X#if debug
  2151. X    printf("Effective copy rate: ");
  2152. X#endif
  2153. X    if (t > 0) {
  2154. X    xfer = nblock * sizeof(buf) * 1000 / t;
  2155. X#if debug
  2156. X    printf("%d bytes/sec\n", xfer);
  2157. X#endif
  2158. X    }
  2159. X#if debug
  2160. X    else
  2161. X    printf(" -- too quick to time!\n");
  2162. X#endif
  2163. X#if awk
  2164. X    fprintf(stderr, " %.2f\n", t > 0 ? (float)xfer/1024 : 0);
  2165. X#endif
  2166. X    exit(0);
  2167. X}
  2168. End-of-File-Grunt
  2169. if test 4352 -ne `cat 'fstime.c' | wc -c`
  2170. then
  2171.     echo 'shar: transmission error (expected 4352 characters)'
  2172. fi
  2173. echo 'x - getwork.c'
  2174. if test -f 'getwork.c'
  2175. then
  2176.     echo 'shar: over-writing existing file getwork.c'
  2177. fi
  2178. sed 's/^X//' > getwork.c <<'End-of-File-Grunt'
  2179. X#include "makework.h"
  2180. X#ifndef lint
  2181. Xstatic char RCSid[] = "$Header: getwork.c,v 1.3 87/06/23 17:01:47 kjmcdonell Beta $";
  2182. X#endif
  2183. X
  2184. X/*
  2185. X * Build data structures (work[0] ... work[want-1]) for the next set
  2186. X * of job streams.
  2187. X */
  2188. X
  2189. Xstream work[MAXSTREAM];
  2190. X
  2191. Xtypedef struct st_cmd {
  2192. X    char    *name;        /* pathname of the command */
  2193. X    char    **argv;        /* command argv[] vector */
  2194. X    struct st_cmd    *next;
  2195. X} cmd;
  2196. X
  2197. Xtypedef struct st_scr {
  2198. X    char    *name;        /* name of the script file */
  2199. X    char    *buf;        /* the text of the script */
  2200. X    int        blen;        /* size of buf[] */
  2201. X    struct st_scr    *next;
  2202. X} scr;
  2203. X
  2204. Xstatic cmd    *cmd_head = (cmd *)0, *cmdp;
  2205. Xstatic scr    *scr_head = (scr *)0, *scrp;
  2206. X
  2207. Xgetwork(want)
  2208. Xint    want;
  2209. X{
  2210. X    int        i;
  2211. X    int        f;
  2212. X    int        ac;
  2213. X    char    *lp;
  2214. X    char    *q;
  2215. X    stream    *w;
  2216. X    char    line[512];
  2217. X    char    c;
  2218. X    int        nwork = 0;
  2219. X    int        new;
  2220. X    char    *malloc(), *realloc();
  2221. X
  2222. X    while (nwork < want) {
  2223. X    if (gets(line) == NULL) {
  2224. X        fprintf(stderr, "Insufficient job streams in the workload file\n");
  2225. X        fflush(stderr);
  2226. X        exit(4);
  2227. X    }
  2228. X    if (nwork >= MAXSTREAM) {
  2229. X        fprintf(stderr, "makework: internal snark -- code is broken!\n");
  2230. X        fflush(stderr);
  2231. X        exit(4);
  2232. X    }
  2233. X    w = &work[nwork];
  2234. X    q = lp = line;
  2235. X    i = 1;
  2236. X    while (*q && *q != ' ') {
  2237. X        i++;
  2238. X        q++;
  2239. X    }
  2240. X    *q = '\0';
  2241. X    if (w->home != (char *)0)
  2242. X        free(w->home);
  2243. X    w->home = (char *)malloc(strlen(lp)+1);
  2244. X    strcpy(w->home, lp);
  2245. X
  2246. X    lp = ++q;
  2247. X    i = 1;
  2248. X    while (*q && *q != ' ') {
  2249. X        i++;
  2250. X        q++;
  2251. X    }
  2252. X    *q++ = '\0';
  2253. X    new = 0;
  2254. X    for (cmdp = cmd_head; cmdp != (cmd *)0; cmdp = cmdp->next) {
  2255. X        if (strcmp(cmdp->name, lp) == 0)
  2256. X        break;
  2257. X    }
  2258. X    if (cmdp == (cmd *)0) {
  2259. X        cmdp = (cmd *)malloc(sizeof(*cmdp));
  2260. X        cmdp->next = cmd_head;
  2261. X        cmd_head = cmdp;
  2262. X        cmdp->name = (char *)malloc(strlen(lp)+1);
  2263. X        strcpy(cmdp->name, lp);
  2264. X        new = 1;
  2265. X        lp = q;
  2266. X        /* start to build arg list */
  2267. X        ac = 2;
  2268. X        cmdp->argv = (char **)malloc(2*sizeof(char *));
  2269. X        q = cmdp->name;
  2270. X        while (*q) q++;
  2271. X        q--;
  2272. X        while (q >= cmdp->name) {
  2273. X        if (*q == '/') {
  2274. X            q++;
  2275. X            break;
  2276. X        }
  2277. X        q--;
  2278. X        }
  2279. X        cmdp->argv[0] = q;
  2280. X    }
  2281. X    else
  2282. X        lp = q;
  2283. X    w->cmd = cmdp->name;
  2284. X    w->av = cmdp->argv;
  2285. X    w->blen = 0;
  2286. X    w->buf = "";
  2287. X    w->tty = "";
  2288. X
  2289. X    while (*lp) {
  2290. X        if (*lp == ' ') {
  2291. X        /* space */
  2292. X        lp++;
  2293. X        continue;
  2294. X        }
  2295. X        else if (*lp == '>') {
  2296. X        /* standard output for this job */
  2297. X        q = ++lp;
  2298. X        while (*q && *q != ' ')
  2299. X            q++;
  2300. X        c = *q;
  2301. X        *q = '\0';
  2302. X        if (w->tty != (char *)0)
  2303. X            free(w->tty);
  2304. X        w->tty = (char *)malloc(strlen(lp)+1);
  2305. X        strcpy(w->tty, lp);
  2306. X        *q = c;
  2307. X        lp = q;
  2308. X        }
  2309. X        else if (*lp == '<') {
  2310. X        /* standard input for this job */
  2311. X        q = ++lp;
  2312. X        while (*q && *q != ' ') q++;
  2313. X        c = *q;
  2314. X        *q = '\0';
  2315. X        for (scrp = scr_head; scrp != (scr *)0; scrp = scrp->next) {
  2316. X            if (strcmp(scrp->name, lp) == 0)
  2317. X            break;
  2318. X        }
  2319. X        if (scrp == (scr *)0) {
  2320. X            scrp = (scr *)malloc(sizeof(*scrp));
  2321. X            scrp->next = scr_head;
  2322. X            scr_head = scrp;
  2323. X            scrp->name = (char *)malloc(strlen(lp)+1);
  2324. X            strcpy(scrp->name, lp);
  2325. X            if ((f = open(lp, 0)) == -1) {
  2326. X            fprintf(stderr, "cannot open input file \"%s\"\n", lp);
  2327. X            fflush(stderr);
  2328. X            exit(4);
  2329. X            }
  2330. X            /* gobble input */
  2331. X            scrp->buf = (char *)malloc(512);
  2332. X            while ((i = read(f, &scrp->buf[scrp->blen], 512)) > 0) {
  2333. X            scrp->blen += i;
  2334. X            scrp->buf = (char *)realloc(scrp->buf, scrp->blen+512);
  2335. X            }
  2336. X            scrp->buf = (char *)realloc(scrp->buf, scrp->blen);
  2337. X            close(f);
  2338. X        }
  2339. X        w->buf = scrp->buf;
  2340. X        w->blen = scrp->blen;
  2341. X        *q = c;
  2342. X        lp = q;
  2343. X        }
  2344. X        else {
  2345. X        /* a command option */
  2346. X        q = lp;
  2347. X        i = 1;
  2348. X        while (*q && *q != ' ') {
  2349. X            q++;
  2350. X            i++;
  2351. X        }
  2352. X        if (new) {
  2353. X            ac++;
  2354. X            cmdp->argv = (char **)realloc(cmdp->argv, ac*sizeof(char *));
  2355. X            cmdp->argv[ac-2] = (char *)malloc(i);
  2356. X            strncpy(cmdp->argv[ac-2], lp, i-1);
  2357. X            cmdp->argv[ac-2][i-1] = '\0';
  2358. X        }
  2359. X        lp = q;
  2360. X        }
  2361. X    }
  2362. X    if (new)
  2363. X        cmdp->argv[ac-1] = (char *)0;
  2364. X        w->av = cmdp->argv;
  2365. X    nwork++;
  2366. X    }
  2367. X}
  2368. End-of-File-Grunt
  2369. if test 3926 -ne `cat 'getwork.c' | wc -c`
  2370. then
  2371.     echo 'shar: transmission error (expected 3926 characters)'
  2372. fi
  2373.